package com.api.gbhg.liuwenbo.action;


import com.api.gbhg.liwenjun.GBHGConstant;
import com.api.gbhg.liwenjun.VersionFlowUtil;
import com.api.gbhg.luoao.tool.ToolCURD;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import weaver.conn.RecordSet;
import weaver.interfaces.workflow.action.Action;
import weaver.soa.workflow.request.RequestInfo;

import java.util.HashMap;
import java.util.Map;

/**
 * 警察在职行政人员工资津贴补经费
 */
public class PolicePersonnelSubsidy implements Action {

    private static final Logger log = LoggerFactory.getLogger("gbhg");

    @Override
    public String execute(RequestInfo requestInfo) {
        RecordSet recordSet = ToolCURD.selectDetailnanlist(requestInfo, 1);
        double yszje = 0;
        while (recordSet.next()){
            String hjwy =  recordSet.getString("hjwy");

            if(!hjwy.isEmpty()){
                yszje = Double.parseDouble(hjwy)+yszje;
                if (yszje<0){
                    yszje=0;
                }
            }
        }

        Map<String,String> map = new HashMap<>();
        map.put("xmmin", "xmmc");

        //同步流程数据到版本表、主表
        boolean isSuccess = VersionFlowUtil.
                sysDataToVersion(requestInfo.getRequestid(), requestInfo.getWorkflowid(),
                        GBHGConstant.FlowVersionTableEnum.uf_jczzxzrygzjtbjfbb, map);

        boolean isUp = ToolCURD.updateVersionQuery( yszje, requestInfo.getRequestid());

        if(!isSuccess&&!isUp){
            log.info("同步流程数据到版本表异常！");
            requestInfo.getRequestManager().setMessagecontent("同步建模表数据异常");
            requestInfo.getRequestManager().setMessageid("1");
            return FAILURE_AND_CONTINUE;
        }
        return SUCCESS;
    }
}
